package com.zcx.qshop.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.TextView;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.qshop.R;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.adapter.RechargeAdapter;
import com.zcx.qshop.conn.JsonRechargeAsyGet;
import com.zcx.qshop.view.TitleView;

import java.util.List;

/**
 * Created by Administrator on 2015/11/16.
 */
public class RechargeActivity extends QSActivity {

    @BoundView(R.id.title_view) private TitleView titleView;

    @BoundView(R.id.recharge_layout) private View layout;

    @BoundView(R.id.recharge_detail) private TextView detail;

    @BoundView(R.id.recharge_grid_view) private GridView gridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_recharge);

        titleView.showStyle(TitleView.Style.FULL);

        titleView.showType(TitleView.Type.BACK_TWO, TitleView.Type.NAME_ONE);

        titleView.setTitleName("充值");

        titleView.setOnTitleItemClickListener(new TitleView.OnTitleItemClickListener() {

            @Override
            public void onBackClick() {

                finish();

            }

        });

        new JsonRechargeAsyGet(new AsyCallBack<List<JsonRechargeAsyGet.Info>>(){

            @Override
            public void onSuccess(String toast, int type, List<JsonRechargeAsyGet.Info> infos) throws Exception {

                layout.setVisibility(View.VISIBLE);

                gridView.setVerticalSpacing(QSApplication.ScaleScreenHelper.getWidthHeight(20));

                gridView.setAdapter(new RechargeAdapter(RechargeActivity.this, infos) {

                    @Override
                    protected void onItemSelect(JsonRechargeAsyGet.Info info) {

                        detail.setText("充" + info.acount + "送" + info.free + "元");

                    }

                });

            }

        }).execute(this);

    }

}
